package com.happyfamily.springboot.crowdsourcingplatform.dao.sun;

import com.happyfamily.springboot.crowdsourcingplatform.model.ServerType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TypeDao
{
	@Select("<script> SELECT * FROM server_type WHERE sparentid=0 " +
			"<when test='limit!=null'> LIMIT #{limit} OFFSET #{end} </when> </script>")
	public abstract List<ServerType> getNeedType(Integer limit, Integer end);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=0")
	public abstract int getNeedSum();

	@Select("<script> SELECT * FROM server_type WHERE sparentid=-1 " +
			"<when test='limit!=null'> LIMIT #{limit} OFFSET #{end} </when> </script>")
	public abstract List<ServerType> getServerType(Integer limit,Integer end);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=-1")
	public abstract int getSererSum();

	@Select(" SELECT * FROM server_type WHERE sparentid=6 " +
			" LIMIT #{limit} OFFSET #{end} ")
	public abstract List<ServerType> getOtherType(Integer limit,Integer end);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=6")
	public abstract int getOtherSum();

	@Insert("INSERT INTO server_type (sname,sparentid) VALUES (#{sname},0)")
	public abstract int addNeedType(String sname);

	@Insert("INSERT INTO server_type (sname,sparentid) VALUES (#{sname},-1)")
	public abstract int addServerType(String sname);

	@Insert("INSERT INTO server_type (sname,sparentid) VALUES (#{sname},6)")
	public abstract int addOtherType(String sname);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=-1 AND sname=#{sname}")
	public abstract int checkServer(String sname);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=0 AND sname=#{sname}")
	public abstract int checkNeed(String sname);

	@Select("SELECT COUNT(*) FROM server_type WHERE sparentid=6 AND sname=#{sname}")
	public abstract int checkOther(String sname);

	@Delete("DELETE FROM server_type WHERE sid=#{sid}")
	public abstract int deleteType(Long sid);

	@Update("UPDATE need SET sname='其他' WHERE sname=#{sname}")
	public abstract int updateNeedType(String sname);

	@Update("UPDATE sys_user SET sid=35 WHERE sid=#{sid}")
	public abstract int updateUserServerType(Long sid);

	@Update("UPDATE alliance SET atype=35 WHERE atype=#{sid}")
	public abstract int updateAlianceServerType(Long sid);
}